package cn.gok.controller;

import cn.gok.controller.dto.MaintainDormitorySearchDTO;
import cn.gok.entity.Student;
import cn.gok.service.IMaintainDormitoryService;
import cn.gok.service.impl.MaintainDormitoryServiceImpl;
import cn.gok.util.ParseRequestParameterUtil;
import cn.gok.util.ResponseUtil;
import cn.gok.util.ResultData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.stream.events.DTD;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @Description: 报修管理
 */
@WebServlet("/maintainDormitory")
public class MaintainDormitoryServlet extends HttpServlet {

    private IMaintainDormitoryService service = new MaintainDormitoryServiceImpl();

    @Override
    protected void service(HttpServletRequest req,
                           HttpServletResponse resp) throws ServletException, IOException {
        String action = req.getParameter("action");

        switch (action){
            case "getMaintainDormitoryList":getMaintainDormitoryList(req, resp);break;
        }
    }

    private void getMaintainDormitoryList(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        MaintainDormitorySearchDTO searchDTO = (MaintainDormitorySearchDTO)ParseRequestParameterUtil.
                parseRequestParam(req.getParameterMap(),MaintainDormitorySearchDTO.class);

        ResultData resultData = null;
        try {
            Integer stuId = ((Student) req.getSession().getAttribute("studentInfo")).getStuId();
            searchDTO.setStuId(stuId);
            resultData = service.getMaintainDormitoryList(searchDTO);

        }catch (Exception e){
            e.printStackTrace();
        }

        ResponseUtil.send(resp,resultData);
    }
}
